/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using VSLangProj80;
using DaveSexton.DocProject.Resources;

namespace DaveSexton.DocProject.Engine
{
	sealed class BuildEngineCollection : KeyedCollection<IDocProject, IBuildEngine>
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="BuildEngineCollection" /> class.
		/// </summary>
		public BuildEngineCollection()
			: base(new ProjectComparer<IDocProject>())
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="BuildEngineCollection" /> class.
		/// </summary>
		public BuildEngineCollection(BuildEngineCollection clone)
			: base(new ProjectComparer<IDocProject>())
		{
			if (clone == null)
				throw new ArgumentNullException("clone");

			for (int i = 0; i < clone.Count; i++)
				Add(clone[i]);
		}
		#endregion

		#region Methods
		protected override void InsertItem(int index, IBuildEngine item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			if (Contains(item))
				throw new ArgumentException(Errors.BuildEngineContained);

			base.InsertItem(index, item);
		}

		protected override void SetItem(int index, IBuildEngine item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			for (int i = 0; i < Count; i++)
				if (index != i && this[i] == item)
					throw new ArgumentException(Errors.BuildEngineContained);

			base.SetItem(index, item);
		}

		protected override IDocProject GetKeyForItem(IBuildEngine item)
		{
			return item.Project;
		}
		#endregion
	}
}
